package com.hdit.mgr
{
	import flash.display.LoaderInfo;  
	import flash.display.Stage;
	import flash.events.ErrorEvent;
	import flash.events.Event;
	import flash.events.UncaughtErrorEvent;
	
	/**
	 * 全局错误管理  
	 **/
	public class GlobalErrorMgr
	{
		public static function init(loaderInfo:LoaderInfo):void
		{
			if(LogMgr.initialized)
			{
				if(!loaderInfo.hasOwnProperty("uncaughtErrorEvents")) 
					return;
				loaderInfo.uncaughtErrorEvents.addEventListener(UncaughtErrorEvent.UNCAUGHT_ERROR, UncaughtError);
				LogMgr.info("全局错误管理初始化完毕!");
			}
		}

		protected static function UncaughtError(event:UncaughtErrorEvent):void
		{
			event.preventDefault(); 
			event.stopImmediatePropagation();
			var message:String=event.error.getStackTrace();
			if (!message)
			{
				if (event.error is Error)
					message=Error(event.error).message;
				else if (event.error is ErrorEvent)
					message=ErrorEvent(event.error).text;
				else
					message=event.error.toString();
			}
			LogMgr.error(message);
		}
	}
}
